package com.demo.zhou.sniper.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.demo.zhou.sniper.module.Zubean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "ZUBEAN".
*/
public class ZubeanDao extends AbstractDao<Zubean, Long> {

    public static final String TABLENAME = "ZUBEAN";

    /**
     * Properties of entity Zubean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Xian = new Property(1, int.class, "xian", false, "XIAN");
        public final static Property Mos = new Property(2, boolean.class, "mos", false, "MOS");
        public final static Property Fanganhao = new Property(3, String.class, "fanganhao", false, "FANGANHAO");
        public final static Property QunId = new Property(4, Long.class, "qunId", false, "QUN_ID");
    }

    private Query<Zubean> qunbean_ZuQuery;

    public ZubeanDao(DaoConfig config) {
        super(config);
    }
    
    public ZubeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"ZUBEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"XIAN\" INTEGER NOT NULL ," + // 1: xian
                "\"MOS\" INTEGER NOT NULL ," + // 2: mos
                "\"FANGANHAO\" TEXT," + // 3: fanganhao
                "\"QUN_ID\" INTEGER);"); // 4: qunId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"ZUBEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, Zubean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getXian());
        stmt.bindLong(3, entity.getMos() ? 1L: 0L);
 
        String fanganhao = entity.getFanganhao();
        if (fanganhao != null) {
            stmt.bindString(4, fanganhao);
        }
 
        Long qunId = entity.getQunId();
        if (qunId != null) {
            stmt.bindLong(5, qunId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Zubean entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getXian());
        stmt.bindLong(3, entity.getMos() ? 1L: 0L);
 
        String fanganhao = entity.getFanganhao();
        if (fanganhao != null) {
            stmt.bindString(4, fanganhao);
        }
 
        Long qunId = entity.getQunId();
        if (qunId != null) {
            stmt.bindLong(5, qunId);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public Zubean readEntity(Cursor cursor, int offset) {
        Zubean entity = new Zubean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // xian
            cursor.getShort(offset + 2) != 0, // mos
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // fanganhao
            cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4) // qunId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Zubean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setXian(cursor.getInt(offset + 1));
        entity.setMos(cursor.getShort(offset + 2) != 0);
        entity.setFanganhao(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setQunId(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Zubean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Zubean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(Zubean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "zu" to-many relationship of Qunbean. */
    public List<Zubean> _queryQunbean_Zu(Long qunId) {
        synchronized (this) {
            if (qunbean_ZuQuery == null) {
                QueryBuilder<Zubean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.QunId.eq(null));
                qunbean_ZuQuery = queryBuilder.build();
            }
        }
        Query<Zubean> query = qunbean_ZuQuery.forCurrentThread();
        query.setParameter(0, qunId);
        return query.list();
    }

}
